/**
 * Created with IntelliJ IDEA.
 *
 * @author: cxs
 * @date: 2023/7/4
 * @time: 9:02
 * @className：CheckController
 * @description：检查单管理
 */
package com.bailan.bus.controller;

import com.bailan.bus.domain.Check;
import com.bailan.bus.domain.Rent;
import com.bailan.bus.service.ICheckService;
import com.bailan.bus.service.IRentService;
import com.bailan.bus.vo.CheckVo;
import com.bailan.common.util.DataGridView;
import com.bailan.common.util.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("check")
public class CheckController {
    @Autowired
    private IRentService rentService;
    @Autowired
    private ICheckService checkService;

    /**
     * 查询出租单是否存在
     * /check/checkRentExist.action
     * @param rentid
     * @return
     */
    @RequestMapping("checkRentExist")
    public Rent checkRentExist(String rentid){
        return rentService.selectRentByRentId(rentid);
    }

    /**
     * 初始化检查单信息
     * @param rentid
     * /check/initCheckFormDate
     * @return
     */
    @RequestMapping("initCheckFormData")
    public Map<String,Object> initCheckFormData(String rentid){
        return checkService.initCheckFormData(rentid);
    }

    /**
     * 保存检查单信息
     * @param checkVo
     * /check/saveCheck.action
     * @return
     */
    @RequestMapping("saveCheck")
    public ResultObj saveCheck(CheckVo checkVo){
        try {
            checkVo.setCreatetime(new Date());
            checkService.addCheck(checkVo);
            return  ResultObj.ADD_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.ADD_ERROR;
        }
    }

    /**
     * 分页查询
     * @param checkVo
     * @return
     */
    @RequestMapping("loadAllCheck")
    public DataGridView loadAllCheck(CheckVo checkVo){
       return  this.checkService.queryAllCheck(checkVo);
    }

    /**
     * 修改
     * @param checkVo
     * @return
     */
    @RequestMapping("updateCheck")
    public ResultObj updateCheck(CheckVo checkVo){
        try{
            this.checkService.updateCheck(checkVo);
            return  ResultObj.UPDATE_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }

    /**
     * 删除
     * @param checkVo
     * @return
     */
    @RequestMapping("deleteCheck")
    public ResultObj deleteCheck(CheckVo checkVo){
        try{
            this.checkService.deleteCheck(checkVo);
            return  ResultObj.UPDATE_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }

    /**
     * 批量删除
     * @param checkVo
     * @return
     */
    @RequestMapping("deleteBatchCheck")
    public ResultObj deleteBatchCheck(CheckVo checkVo){
        try{
            this.checkService.deleteBatchCheck(checkVo.getIds());
            return  ResultObj.UPDATE_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }
}
